var element_y;
var swiffy;
var cur_groupid;
var group_sortable = new Array();
var lightbox;
var content;

window.addEvent('load', function() {
	checkScrollerWidth();
	checkImages();
});

function checkImages() {
	var check_w = window.getSize().x + 500;

	var divs = $$('.single_image_holder');
	for(var i=0; i<divs.length; i++) {
		if(divs[i].getChildren().length) continue;
		if((parseInt($('main_images').getPosition().x) + parseInt(divs[i].get('xpos'))) >= check_w) return;
		var img = new Element('img', {
			'src': divs[i].get('source')
		});
		divs[i].adopt(img);
	}
}

window.addEvent('resize', function(){			
	checkScrollerWidth();
});

function checkScrollerWidth() {
	if($('scrollbar2') && $('content2') && $('handle2'))
	makeScrollbar( $('content2'), $('main_images'), $('scrollbar2'), $('handle2'), true);
}

function makeScrollbar(content,checkContent,scrollbar,handle,horizontal,ignoreMouse){
	
	if(checkContent.getScrollSize().x < scrollbar.getSize().x) {
		handle.setStyle('display','none');
		return;
	}
	
	handle.setStyle('display','block');

    var steps = (horizontal ? (content.getScrollSize().x - content.getSize().x) : (content.getScrollSize().y - content.getSize().y));
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
			checkImages();
		}
	}).set(0);


  content.addEvent('DOMMouseScroll', function(e){	
		e = new Event(e).stop();
		var step = slider.step - e.wheel * 30;	
		slider.set(step);
	});

	content.addEvent('mousewheel', function(e){	
	    e = new Event(e).stop();
		var step = slider.step - e.wheel * 30;	
		slider.set(step);					
	});
}